import baseApi from '@/api/api'
// import { getToken, setToken, removeToken } from '@/utils/login'
import * as types from './mutation-types'

const state = {

	ownInfo: {}, // 当前用户信息
    auditState:null //审核状态

}

const getters = {

	ownInfo: state => state.ownInfo, // 用户信息
}

const mutations = {

	[types.GET_OWNINFO](state, payload) {
	  // 更新个人信息
	  state.ownInfo = payload
	},
}

const actions = {
	  //账号密码登录
	  userLogin({ commit }, param) {
		return baseApi.userLogin(param).then(res => {
		  uni.setStorageSync('token',res.data.data.token)
		  commit(types.GET_OWNINFO, res.data.data.userInfo)
		  uni.setStorageSync('userInfo',res.data.data.userInfo)
		  return res
		})
	  },
	  //手机验证码登录
	  telLogin({ commit }, param) {
	  		return baseApi.telLogin(param).then(res => {
	  		  uni.setStorageSync('token',res.data.data.token)
	  		  commit(types.GET_OWNINFO, res.data.data.userInfo)
			  uni.setStorageSync('userInfo',res.data.data.userInfo)
	  		  return res
	  		})
	  },
	  //小程序端解密
	  decryptData({ commit }, param){
	  		return baseApi.decryptData(param).then(res => {
	  		  return res
	  		})
	  },
	  //小程序端微信授权登录
	  wxLogin({ commit }, param) {
	  		return baseApi.wxLogin(param).then(res => {
	  		  return res
	  		})
	  },
	//发送手机验证码
	sendCaptcha({ commit }, param) {
	  return baseApi.sendCaptcha(param).then((res) => {
		return res
	  })
	},
	//重置密码
	resetPwd({ commit }, param) {
			return baseApi.resetPwd(param).then(res => {
			  return res
			})
	},
	//加工厂注册
	registerFactory({ commit }, param){
		return baseApi.registerFactory(param).then((res) => {
				return res
		})
	},
	//获取当前加工厂的信息
	getCurrentFactory({ commit }, param){
		return baseApi.getCurrentFactory(param).then((res) => {
				uni.setStorageSync('factoryinfo',res.data.data)
				return res
		})
	},
	//共享工厂用户-获取个人信息
	getSfactoryUserInfo({ commit }, param){
		return baseApi.getSfactoryUserInfo(param).then((res) => {
				uni.setStorageSync('factoryinfo',res.data.data)
				return res
		})
	},
	//加工厂-完善资料|修改信息
	addOrUpdateFactory({ commit }, param){
		return baseApi.addOrUpdateFactory(param).then((res) => {
				return res
		})
	},
	//获取上传图片token
	getUploadFileToken({
		commit
	}, param) {
		return baseApi.getUploadFileToken(param).then(res => {
			return res
		})
	}

}

export default {
	// namespaced: true,
	state,
	getters,
	mutations,
	actions
}
